;V9990 ZOOM
;
;This one for ZOOM <1
;
;HG 1994
;
;

wait	macro
	IN A,(#65)
	RRCA
	DB #38,#FB
	endm

setreg	macro @val
	if "@val">""
	ld a,@val
	endif
	out (#64),a
	endm

outreg	macro @val
	if "@val">""
	ld a,@val
	endif
	out (#63),a
	endm

ActPage equ #FAF6


BLOAD:	DB #FE
	DW BEGIN	
	DW END
	DW BEGIN
	ORG #D000
BEGIN:	JP MAIN

ZoomTab:DW #0800
	DW #0010
	DB 0			;Center-X (N.U.)
	DB 0			;Center-Y (N.U.)

Main:	LD IX,ZoomTab
	JP ZoomIn


ZoomIn: LD E,(IX)
	LD D,(IX+1)
ZumIn1: LD HL,0 		;SX * 256
	LD B,0			;DY
ZumIn2: ld a,(#fbec)
	and 4
	ret z
	CALL COPYX1
	INC B			;Increase DX
	ADD HL,DE		;Increase SX with invers Zoom factor
	JR NC,ZumIn2

	LD C,0			;DY
	LD HL,0 		;SY
ZumIn3: ld a,(#fbec)
	and 4
	ret z
	CALL CopyY1
	INC C			;Increase DY
	ADD HL,DE		;Increase SY with invers ZOOM factor
	LD A,H
	CP 211
	JR C,ZumIn3

	LD C,(IX+2)		;Change Zoom-Factor
	LD B,(IX+3)
	EX DE,HL
	SBC HL,BC
	EX DE,HL
	LD A,D
	AND A
	JR NZ,ZumIn1
	RET

CopyX1: IN A,(#65)
	RRCA
	JR C,CopyX1
	SETREG 32
	OUTREG H
	OUTREG 0
	OUTREG
	OUTREG
	OUTREG B
	OUTREG 0
	OUTREG
	OUTREG 1
	OUTREG
	OUTREG 0
	OUTREG 212
	OUTREG 0
	SETREG 52
	OUTREG #40
	RET

CopyY1: IN A,(#65)
	RRCA
	JR C,CopyY1
	SETREG 32
	OUTREG 0		;SX
	OUTREG
	OUTREG H		;SY
	OUTREG 1
	OUTREG 0		;DX
	OUTREG
	OUTREG C		;DY
	OUTREG (ActPage)
	OUTREG B		;NX
	OUTREG 0
	OUTREG 1		;NY
	OUTREG 0
	SETREG 52
	OUTREG #40
	RET

END:	nop
